package com.yc.jpyy.common.controller;

import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.common.utils.manydatasource.HandlerDataSource;
import com.yc.jpyy.base.controller.BaseController;

@Controller
@RequestMapping(value = "/getTime")
@Scope("prototype")
public class GetSystemTime extends BaseController{

	 private static Logger logger = LoggerFactory.getLogger(GetSystemTime.class);
		
	 //获取系统时间
		@SuppressWarnings("finally")
		@RequestMapping(value = "/getSystemTime", method = { RequestMethod.GET,
				RequestMethod.POST }, produces = "application/json; charset=utf-8")
		public @ResponseBody String getSystemTime(HttpServletRequest request) throws UnsupportedEncodingException {
			Map<String,Object> resultMap = new HashMap<>();
			try{
				DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
				LocalDateTime time = LocalDateTime.now();
				resultMap.put("ListData", df.format(time));
				resultMap.put("returnCode", 1);
				resultMap.put("returnMsg", "操作成功");
			} catch (Exception e) {
				logger.info("addDataAcquisition" + e.toString());
				resultMap.put("returnCode", 0);
				resultMap.put("returnMsg", "获取失败");
			}
			finally {
				HandlerDataSource.clear();
				return JSON.toJSONString(resultMap);
			}
			
		}
}
